# coding: utf-8
from typing import Union

from PySide6.QtGui import QPixmap, QImage
from PySide6.QtWidgets import QHBoxLayout

from common import OthersIcon
from components import ScrollAreaWidget, PodcastGalleryWidget
from .music import SongInfoCard, LyricCardWidget


class SingerInfoView(ScrollAreaWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.horizontalLayout = QHBoxLayout()
        self.infoCard = SongInfoCard(self)
        self.lyricCardWidget = LyricCardWidget(self)
        self.galleryWidget = PodcastGalleryWidget(self)

        self.__initWidgets()

        self.setLyric('暂无歌词')
        self.lyricCardWidget.setSongInfo(
            '精选好歌',
            [
                {
                    'image': OthersIcon.Default.path(),
                    'name': '野孩子',
                    'singer': '杨千嬅'
                },
                {
                    'image': OthersIcon.Default.path(),
                    'name': '处处吻',
                    'singer': '杨千嬅'
                },
                {
                    'image': OthersIcon.Default.path(),
                    'name': '小城大事',
                    'singer': '杨千嬅'
                },
                {
                    'image': OthersIcon.Default.path(),
                    'name': '可惜我是水瓶座',
                    'singer': '杨千嬅'
                }
            ]
        )
        self.lyricCardWidget.setSongInfo(
            '精选好歌',
            [
                {
                    'image': OthersIcon.Default.path(),
                    'name': '野孩子',
                    'singer': '杨千嬅'
                },
                {
                    'image': OthersIcon.Default.path(),
                    'name': '处处吻',
                    'singer': '杨千嬅'
                },
                {
                    'image': OthersIcon.Default.path(),
                    'name': '小城大事',
                    'singer': '杨千嬅'
                },
                {
                    'image': OthersIcon.Default.path(),
                    'name': '可惜我是水瓶座',
                    'singer': '杨千嬅'
                }
            ]
        )

        self.addGalleryWidget(
            title='本周排行',
            cards=[
                {
                    'pixmap': OthersIcon.Default.path(),
                    'title': 'Sunday Morning',
                    'body': '余杰'
                } for i in range(10)
            ]
        )

    def __initWidgets(self):
        self.setObjectName('SingerInfoView')
        self.infoCard.setFixedHeight(400)
        self.galleryWidget.setFixedHeight(350)
        self.verticalLayout.addWidget(self.infoCard)
        self.verticalLayout.addWidget(self.lyricCardWidget)
        self.verticalLayout.addLayout(self.horizontalLayout)
        self.verticalLayout.addWidget(self.galleryWidget)

    def setLyric(self, lyric: str):
        self.lyricCardWidget.setLyric(lyric)

    def setSongInfo(self, image: Union[str, QPixmap, QImage], name: str, singer: str, length: str, time: str):
        """
        设置歌曲信息
        :param image:
        :param name:
        :param singer:
        :param length:
        :param time:
        :return:
        """
        self.infoCard.setSongInfo(image, name, singer, length, time)

    def addGalleryWidget(self, title: str, cards: list = None, singers: list = None):
        self.galleryWidget.setTitle(title)
        if cards:
            for card in cards:
                self.galleryWidget.addCard(**card)
        if singers:
            for singer in singers:
                self.galleryWidget.addSinger(**singer)
